<?php

class Application_Model_ApostasAbertasMapper
{
    protected $_dbTable;

    public function setDBTable($tabelaBD)
    {
        if(is_string($tabelaBD)){
            $tabelaBD = new $tabelaBD();
        }
        if (!$tabelaBD instanceof Zend_Db_Table_Abstract) {
            throw new Exception('Tabela invalida');
        }
        $this->_dbTable = $tabelaBD;
        return $this;
    }

    public function getDBTable()
    {
        if (null == $this->_dbTable) {
            $this->setDBTable('Application_Model_DbTable_ApostasAbertas');
        }
        return $this->_dbTable;
    }

    public function getApostasAbertas($email)
    {
        $tabela = $this->getDBTable();

        $select = $tabela->select();
        $select->from($tabela, '*')
               ->where('email_usuario = ?', $email);

        $linha =  $tabela->fetchAll($select);

        return count($linha);
    }

    public function getApostadores($id_bolao, $id_jogo)
    {
        $tabela = $this->getDBTable();

        $select = $tabela->select();
        $select->from($tabela, '*')
               ->where('id_bolao = ?', $id_bolao)
               ->where('id_jogo = ?', $id_jogo)
               ->limit(30, 0);


        $linha =  $tabela->fetchAll($select);

        return $linha;
    }

}

